<!-- 首页 -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>首页</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
    <link rel="stylesheet" href="./xznstatic/css/common.css"/>
    <link rel="stylesheet" href="./xznstatic/css/style.css"/>
</head>
<style type="text/css">
    html, body {
        height: 100%;
        background-color: rgba(238, 238, 238, 1); /* 设置背景颜色 */
    }

    #iframe {
        width: 100%;
        margin-top: 60px;
        padding-top: 80px;
    }

    #header {
        height: auto;
        background: #fff;
        border-bottom: 0;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
    }

    #header .nav-top {
        display: flex;
        align-items: center;
        padding: 0 20px;
        font-size: 16px;
        color: #2a8a15;
        box-sizing: border-box;
        height: 60px;
        background-color: rgba(245, 245, 245, 1);
        box-shadow: 0 0px 0px rgba(0, 0, 0, .3);
        justify-content: space-between;
        position: relative;
    }

    #header .nav-top-img {
        width: 124px;
        height: 40px;
        padding: 0;
        margin: 0;
        border-radius: 6px;
        border-width: 0;
        border-style: solid;
        border-color: rgba(0, 0, 0, .3);
        box-shadow: 0 0 6px rgba(0, 0, 0, .3);
    }

    #header .nav-top-title {
        line-height: 45px;
        font-size: 30px;
        color: rgba(19, 175, 105, 1);
        padding: 0 10px;
        margin: 0 10px;
        border-radius: 6px;
        border-width: 0;
        border-style: solid;
        border-color: rgba(0, 0, 0, .3);
        box-shadow: 0 0 0px rgba(0, 0, 0, .3);
    }

    #header .nav-top-tel {
        line-height: 40px;
        font-size: 16px;
        color: rgba(19, 175, 105, 1);
        padding: 0 10px;
        margin: 0;
        border-radius: 6px;
        border-width: 1px;
        border-style: solid;
        border-color: rgba(19, 175, 105, 1);
        box-shadow: 0 0 2px rgba(0, 0, 0, .3);
    }

    #header .navs {
        display: flex;
        padding: 0 20px;
        align-items: center;
        box-sizing: border-box;
        height: 80px;
        background-color: rgba(256, 256, 256, 1);
        justify-content: flex-end; /* 右对齐 */
    }

    #header .navs .title {
        width: auto;
        line-height: 40px;
        font-size: 16px;
        color: #333;
        padding: 0 10px;
        margin: 0 5px;
        border-radius: 6px;
        border-width: 0;
        border-style: solid;
        border-color: rgba(0, 0, 0, .3);
        box-shadow: 0 0 6px rgba(0, 0, 0, 0);
    }

    #header .navs li {
        display: inline-block;
        width: auto;
        line-height: 80px; /* 调整行高 */
        padding: 0 10px;
        margin: 0 5px;
        color: black;
        font-size: 16px;
        border-radius: 0px;
        border-width: 0;
        border-style: solid;
        border-color: rgba(0, 0, 0, .3);
        background-color: #ffffff;

        text-align: center;
    }

    #header .navs li a {
        color: inherit;
    }

    #header .navs li.current a,
    #header .navs li a:hover {
        color: inherit;
    }

    #header .navs li.current {
        color: rgba(255, 255, 255, 1);
        font-size: 16px;
        border-radius: 0px;
        border-width: 0;
        border-style: solid;
        border-color: rgba(19, 175, 105, 1);
        background-color: rgba(19, 175, 105, 1);
        box-shadow: 0 0 0px rgba(255, 0, 0, .8);
    }

    #header .navs li:hover {
        color: #fff;
        border-radius: 0px;
        border-width: 0;
        border-style: solid;
        border-color: rgba(19, 175, 105, 1);
        background-color: rgba(19, 175, 105, 1);
    }

    .copyright {
        text-align: center;
        line-height: 26px;
        color: black;
    }

    .copyright a {
        color: black
    }
</style>
<body>
<!-- start 顶部导航栏 -->
<div id="app" style="max-width: 1240px;margin: 0 auto">
    <div id="header">
        <div class="navs">
            <!-- <div class="logo" style="font-size: 20px;top: 32px;color: #fff;font-weight: bold;margin-left: -200px;width: 240px;" v-text="projectName"></div> -->
            <div class="title" v-if="false" v-text="projectName"></div>
            <div class="list">
                <ul>
                    <li class='current'><a href="javascript:navPage('./pages/home/home.html')" class="menumain"><i
                            v-if="false" class="layui-icon layui-icon-home"></i>首页</a></li>
                    <li v-for="(item,index) in indexNav" v-bind:key="index"><a
                            :href="'javascript:navPage(\''+item.url+'\')'" class="menumain" style="cursor: pointer;"><i
                            v-if="false" class="layui-icon" :class="iconArr[index]"></i>{{item.name}}</a></li>
                    <li><a href="javascript:centerPage();" class="menumain"><i v-if="false"
                                                                               class="layui-icon layui-icon-username"></i>个人中心</a>
                    </li>
                    <li><a :href="adminurl" target="_blank" class="menumain" style="cursor: pointer;"><i v-if="false"
                                                                                                         class="layui-icon layui-icon-link"></i>后台管理</a>
                    </li>
                    <li v-if="cartFlag"><a href="javascript:navPage('./pages/shop-cart/list.html')" class="menumain"><i
                            v-if="false" class="layui-icon">&#xe657;</i>购物车</a></li>
                    <li v-if="chatFlag"><a href="javascript:chatTap()" class="menumain"><i v-if="false"
                                                                                           class="layui-icon">&#xe677;</i>在线客服</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!-- end 顶部导航栏 -->

    <iframe src="./pages/home/home.html" id="iframe" frameborder="0" scrolling="no" width="100%"
            onload="changeFrameHeight"></iframe>

    <div class="copyright">
        <p>
            <a href="#">关于我们</a>|
            <a href="#">帮助中心</a>|
            <a href="#">售后服务</a>|
            <a href="#">配送与验收</a>|
            <a href="#">商务合作</a>|
            <a href="#">搜索推荐</a>|
            <a href="#">友情链接</a>
        </p>
        <p>CopyRight © 医护</p>
    </div>
</div>

<script src="./xznstatic/js/jquery-1.11.3.min.js"></script>
<script src="./layui/layui.js"></script>
<script src="./js/vue.js"></script>
<script src="./js/config.js"></script>

<script>
    var vue1 = new Vue({el: '#tabbar'})

    var vue = new Vue({
        el: '#header',
        data: {
            iconArr: ['layui-icon-gift', 'layui-icon-email', 'layui-icon-logout', 'layui-icon-transfer', 'layui-icon-slider', 'layui-icon-print', 'layui-icon-cols', 'layui-icon-snowflake', 'layui-icon-note', 'layui-icon-flag', 'layui-icon-theme', 'layui-icon-website', 'layui-icon-console', 'layui-icon-face-surprised', 'layui-icon-template-1', 'layui-icon-app', 'layui-icon-read', 'layui-icon-component', 'layui-icon-file-b', 'layui-icon-unlink', 'layui-icon-tabs', 'layui-icon-form', 'layui-icon-chat'],
            indexNav: indexNav,
            cartFlag: cartFlag,
            adminurl: adminurl,
            chatFlag: chatFlag,
            projectName: projectName,
        },
        mounted: function () {
            this.bindClickOnLi();
        },
        created() {
            this.iconArr.sort(() => {
                return (0.5 - Math.random())
            })
        },
        methods: {
            jump(url) {
                jump(url)
            },
            bindClickOnLi() {
                let list = document.getElementsByTagName("li");
                for (var i = 0; i < list.length; i++) {
                    list[i].onclick = function () {
                        $(this).addClass("current").siblings().removeClass("current");
                    }
                }
            }
        }
    });

    layui.use(['element', 'layer'], function () {
        var element = layui.element;
        var layer = layui.layer;
    });

    function chatTap() {
        var userTable = localStorage.getItem('userTable');
        if (userTable) {
            layui.layer.open({
                type: 2,
                title: '在线客服',
                area: ['600px', '600px'],
                content: './pages/chat/chat.html'
            });
        } else {
            window.location.href = './pages/login/login.html'
        }
    }

    // 导航栏跳转
    function navPage(url) {
        localStorage.setItem('iframeUrl', url);
        document.getElementById('iframe').src = url;
    }

    // 跳转到个人中心也
    function centerPage() {
        var userTable = localStorage.getItem('userTable');
        if (userTable) {
            localStorage.setItem('iframeUrl', './pages/' + userTable + '/center.html');
            document.getElementById('iframe').src = './pages/' + userTable + '/center.html';
        } else {
            window.location.href = './pages/login/login.html'
        }
    }

    var iframeUrl = localStorage.getItem('iframeUrl');
    document.getElementById('iframe').src = iframeUrl || './pages/home/home.html';

    // var i = 0;
    setInterval(function () {
        // i++;
        // if(i<50) changeFrameHeight();
        changeFrameHeight();
    }, 200)

    function changeFrameHeight() {
        var iframe = document.getElementById('iframe');
        // iframe.height = 'auto';
        if (iframe) {
            var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
            if (iframeWin.document.body) {
                iframe.height = iframeWin.document.body.scrollHeight;
            }
        }
    };

    //  窗口变化时候iframe自适应
    // function changeFrameHeight() {
    // var header = document.getElementById('header').scrollHeight;
    //     let isshow = true
    //     var tabbar = 0
    //     if(isshow) {
    //       tabbar = document.getElementById('tabbar').scrollHeight
    //     }
    // var ifm = document.getElementById("iframe");
    // ifm.height = document.documentElement.clientHeight - header - tabbar;
    // ifm.width = document.documentElement.clientWidth;
    // }

    // reasize 事件 窗口大小变化后执行的方法
    window.onresize = function () {
        changeFrameHeight();
    }
</script>
</body>
</html>
